<?php
namespace app\manager\controller;
use think\Controller;
use think\Request;
use \app\common\traits\controller\TraitController;
/**
 * 管理员个人中心控制器
 */
class ManagerInfo extends BaseController
{
    public function getResetPwd()
    {
        $id = session('manager.id');
        $this->assign('id',$id);
        return view('p/managerinfo/resetpwd');
    }
    //修改密码
    public function postResetPwd()
    {
        $id = session('manager.id');
        $oldpwd = md5(input('post.oldpwd'));
        $password = md5(input('post.password'));
        $password1 = md5(input('post.password1'));
        $pwd = model('CampManagers')->where('id',$id)->where('password',$oldpwd)->find();
        if ($pwd == '') {
            return $this->error('原密码错误');
        }
        if ($password !=$password1) {
            return $this->error('两次输入的密码不一致');
        }

        $count = model('CampManagers')->resetPwd($id,$password);
        if ($count) {
            return $this->success('修改密码成功','/campmanagerlist');
        }
        return $this->error('修改密码失败');
    }

    public function getManagerInfo()
    {
        $id = session('manager.id');
        $data = model('CampManagers')->getCampManagerInfo($id);
        $this->assign('data',$data);
        $this->assign('id',$id);
        return view('p/managerinfo/managerinfo');
    }

    //修改个人资料
    public function postManagerInfo()
    {
        $id = session('manager.id');
        $post_campmanager_info['name'] = input('post.name');
        $post_campmanager_info['phone'] = input('post.phone');
        $post_campmanager_info['email'] = input('post.email');
        $post_campmanager_info['idnumber'] = input('post.idnumber');
        $post_campmanager_info['remark'] = input('post.remark');
        $campmanager = model('CampManagers')->updateCampManagerInfo($id, $post_campmanager_info);

        if($campmanager){
            return $this->success('更新成功','/campmanagerlist');
        }
            return $this->error('更新失败');
    }
}
